<template>
  <div @click="courseClick" v-if="showCourse">
    <div class="c-top">
      <img :src="course.material.cover" class="course-cover-img">
      <div class="mask"></div>
      <div class="details">
        <span class="price">
          {{ course.price }}元
        </span>
        <span class="sign" v-if="course.order_id">
          {{ course.statusTitle }} {{ orderTitle }}
        </span>
        <span class="sign" v-else>
          ({{ course.count_data.sign_up_num }}/{{ course.total }}) {{ course.statusTitle }}
        </span>
      </div>
    </div>
    <div class="cl-module c-detail-info">
      <div class="cl-m-body">
        <div class="apply-detail">
          <p>
            {{ course.title }}
          </p>
          <ul class="label-list">
            <li>{{ course.ageLabel }}</li>
            <li>{{ course.themeLabel }}</li>
            <li>{{ course.targetLabel }}</li>
            <li>{{ course.sceneLabel }}</li>
          </ul>
          <p class="clear">
            <span>报名时间</span>
            <span>{{ course.sign_up_time }}</span>
          </p>
          <p>
            <span>上课时间</span>
            <span>{{ course.lesson_time }}</span>
          </p>
          <p>
            <span>上课地点</span>
            <span>{{ course.lesson_location }}</span>
          </p>
          <div class="course-btn" v-if="course.order_id">
            <div v-if="course.order_status === 0">
              <span class="order-btn" v-if="course.channel_id === 0" @click.stop="pay">支付</span>
              <span v-else>待确认</span>
            </div>
            <div v-if="course.order_status === 1">
              <span class="order-btn" @click.stop="giveUp">放弃</span>
            </div>
            <div v-if="course.order_status === 5">
              <span class="order-btn" @click.stop="openCourse">打开</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      showCourse: true
    }
  },
  props: {
    course: {},
    linkDisabel: {
      default: false
    }
  },
  computed: {
    orderTitle () {
      var result = ''
      if (this.course.order_status === 0) {
        result = this.course.channel_id > 0 ? '未确认' : '未支付'
      } else if (this.course.order_status === 0) {
        result = this.course.channel_id > 0 ? '已确认' : '已支付'
      } else {
        result = this.$config.status.order[this.course.order_status]
      }
      return result
    }
  },
  methods: {
    courseClick () {
      if (this.linkDisabel) {
        return
      }
      console.log('courseClick')
      var url = this.course.link
      this.$router.push(url)
    },
    pay () {
      window.location.href = 'http://wx.xinjijiaoyu.com/#/parent/course/pay/' + this.course.order_id
      // this.$router.push('/parent/course/pay/' + this.course.order_id)
    },
    giveUp () {
      this.showConfirm('确定放弃课程吗？', () => {
        this.$api.order.giveUp(this.course.order_id).then(() => {
          this.showSuccess('操作成功')
          // this.$router.push('/parent/course/manage/2')
          this.showCourse = false
        }).catch((e) => {
          this.showError(e.message)
        })
      })
    },
    openCourse () {
      // 开始上课
      if (this.course.status < 9) {
        this.$router.push('/parent/course/course_material/' + this.course.id)
      } else {
        this.$router.push('/parent/course/after_class/' + this.course.id)
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.c-top{
  position: relative;
  line-height: 0px;

  img {
      width: 100%;
      z-index: 0;
  }
  .mask{
    width: 100%;
    height:100%;
    position: absolute;
    top: 0px;
    bottom:0px;
    z-index: 1;
    background-image: linear-gradient(bottom, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0) 100%);
  }
  .details {
    position: absolute;
    width:100%;
    bottom:10px;
    color: #ffffff;
    z-index: 5;
    line-height: 20px;
  }
  .price {
    margin-left: 15px;
  }
  .sign {
    float: right;
    margin-right: 15px;
  }
}

li {
    list-style: none;
}
.label-list li {
    float: left;
    color: #00a6ac;
    margin-right: 15px;
    margin-top: 5px;
    margin-bottom: 5px;
}

div.c-detail-info{
  margin-top: -15px;
  background-color: #00a6ac;
}
.cl-m-body {
    margin-left: 6px;
    padding-left: 21px;
    background-color: #fff;
    p {
        margin-top: 10px;
        span {
            margin-right: 10px;
        }
        span:nth-child(odd) {
            color: #6c7b8a;
        }
        span:nth-child(even) {
            color: #323b46;
        }
    }
}
.apply-detail{
  position: relative;
}
.course-btn{
  position: absolute;
  top:50%;
  right:0;
}
.course-btn span{
  display: inline-block;
  height: 57px;
  line-height: 57px;
  text-align: center;
  width: 60px;
  color: #60c9cf;
}
.course-btn .order-btn{
  box-shadow: 0 -1px 2px 0 #60c9cf;
  border-radius: 50px;
}
</style>
